package edu.wichita.weighin;

import android.app.DialogFragment;
import android.os.Bundle;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Toast;

public class ChooseMetalDialogFragment extends DialogFragment implements OnItemClickListener {

    String[] listitems = { "GOLD 24K", "GOLD 23K", "GOLD 22K", "GOLD 18K", "GOLD 14K", "SILVER", "PLATINUM" };
    ListView mylist;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
            View view = inflater.inflate(R.layout.dialog_fragment, null, false);
        mylist = (ListView) view.findViewById(R.id.list);
        getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
        return view;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),
        android.R.layout.simple_list_item_1, listitems);

        mylist.setAdapter(adapter);
        mylist.setOnItemClickListener(this);
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        MetalResultsActivity callingActivity = (MetalResultsActivity) getActivity();
        callingActivity.onUserSelectValue(listitems[position]);
        dismiss();
        Toast.makeText(getActivity(), listitems[position], Toast.LENGTH_SHORT).show();
    }
}